package HOT100;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2022/09/13 20:03
 **/
public class baiduII {
    public static void main(String[] args) {
        String[] s= new String[5];
        System.out.println(s[0]);
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            BigInteger[] arr = new BigInteger[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = sc.nextBigInteger();
            }
            BigInteger mp = BigInteger.valueOf(0);
            int i = 0;
            while (i < n - 2) {
                while (arr[i].compareTo(BigInteger.valueOf(1)) >= 0 && arr[i + 1].compareTo(BigInteger.valueOf(2)) >= 0 && arr[i + 2].compareTo(BigInteger.valueOf(3)) >= 0) {
                    arr[i] = arr[i].add(BigInteger.valueOf(-1));
                    arr[i + 1] = arr[i + 1].add(BigInteger.valueOf(-2));
                    arr[i + 2] = arr[i + 2].add(BigInteger.valueOf(-3));
                    mp = mp.add(BigInteger.valueOf(5));
                }
                i++;
            }
            for (BigInteger k : arr) {
                mp = mp.add(k);
            }
            System.out.println(mp);
        }
    }
}